import http from "@/utils/request";
import type { IRes } from "@/interface/index";
// export const test = (data) => {
//   return request.get('/user', data)
// }

// extends IRes：意思是继承 IRes
interface IgetImageCode extends IRes {
  data: {
    bigWidth: number,
    bigHeight: number,
    bigImageBase64: string,
    bigImage: null,
    posY: null,
    posX: null,
    smallWidth: number,
    smallHeight: number,
    smallImageBase64: string,
    smallImage: null
  }
}
// 获取图片验证码
export const getImageCode = (data: any) => {
  // 接口前需加上/api/xlx-sso
  return http.post<IgetImageCode>('/api/xlx-sso/user/getImageCode', data)
}
interface iImageCode {
  movePosX: string,
  phone: string
}
interface ILoginRes extends IRes {
  data: boolean
}
// 校验滑块图形验证并发送验证码
export const verifyImageCode = (data: iImageCode) => {
  return http.post<ILoginRes>('/api/xlx-sso/user/verifyImageCode', data)
}
// 前端给后端的数据类型
interface ILoginVerification {
  phone: string,
  verification: string
}
// 后端返回前端数据的类型
interface ILoginVerificationData extends IRes {
  data: {
    token: string,
    isNew: boolean
  }
}
// 验证码登录
export const loginVerification = (data: ILoginVerification) => {
  return http.post<ILoginVerificationData>('/api/xlx-sso/user/loginVerification', data)
}
interface ILoginParam extends IRes {
  data: {
    redirectUri: string,
    appid: string,
    scope: string,
    state: string
  }
}
// 微信登录-获取微信参数
export const getLoginParam = () => {
  return http.get<ILoginParam>('/api/xlx-sso/oauth/wechat/getLoginParam')
}
export interface IuserLogin {
  mobile: string;
  password: string
}
interface IuserLoginData extends IRes {
  data: {
    created: string | null //创建时间
    updated: string | null //更新时间
    id: number
    mobile: string //用户手机号
    password: string | null
    token: string
  }
}
// 账号密码登录
export const userLogin = (data: IuserLogin) => {
  return http.post<IuserLoginData>('/api/xlx-sso/user/login', data)
}